package com.trussell.genesis.windowutils.menus;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenu;
import javax.swing.JMenuItem;

import com.trussell.genesis.GenesisImplementor;

/**
 * This class helps reduce the number of lines of code
 * in Genesis.java by taking the GUI and controller 
 * construction of the View menu and placing it into
 * this class.
 * @author Tyler Trussell
 */
public class ViewMenu extends JMenu {
	
	private static final long serialVersionUID = 1L;

	/**
	 * Returns a GenesisViewMenu, which contains the prepared
	 * JMenuItems necessary. They have already been bound to
	 * listeners.
	 */
	public ViewMenu() {
		super("View");
		
		JCheckBoxMenuItem lighting = new JCheckBoxMenuItem("Lighting", true);
		JCheckBoxMenuItem shadows = new JCheckBoxMenuItem("Shadows", true);
		JCheckBoxMenuItem water = new JCheckBoxMenuItem("Water", true);
		JCheckBoxMenuItem bloom = new JCheckBoxMenuItem("Bloom", true);
		JCheckBoxMenuItem textures = new JCheckBoxMenuItem("Textures", true);
		JCheckBoxMenuItem wireframe = new JCheckBoxMenuItem("Wireframe", false);
		JMenuItem snapToOrigin = new JMenuItem("Camera to Origin");
		JMenuItem hideMenus = new JMenuItem("Hide Menus");
		
		lighting.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				GenesisImplementor.getInstance().setLighting(((JCheckBoxMenuItem)arg0
						.getSource()).isSelected());
			}
		});
		
		shadows.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				GenesisImplementor.getInstance().setShadows(((JCheckBoxMenuItem)arg0
						.getSource()).isSelected());
			}
		});
		
		wireframe.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				GenesisImplementor.getInstance().setWireframe(((JCheckBoxMenuItem)arg0
						.getSource()).isSelected());
			}
		});
		
		add(lighting);
		add(shadows);
		add(water);
		add(bloom);
		addSeparator();
		add(textures);
		add(wireframe);
		addSeparator();
		add(snapToOrigin);
		add(hideMenus);
	}

}
